package com.flash.InventoryManagement.controller;

import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import com.flash.InventoryManagement.entity.CashStock;
import com.flash.InventoryManagement.entity.TaStock;
import com.flash.InventoryManagement.service.TaStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/9/1
 */
@Controller
public class TaStockContrller {

    @Autowired
    TaStockService taStockService;

    @Resource
    Dbutil dbutil;

    @RequestMapping("selectTaStock")
    @ResponseBody
    public Map selectTaStock(TaStock taStock, int page, int limit) {
        System.out.println("查询Ta库存");
        Map map = new HashMap();
        List taStocklist = taStockService.selectTaStock(taStock, page, limit);
        //记录总条数
        int count = taStockService.countTaStock();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", taStocklist);
        return map;
    }

    @RequestMapping("insertTaStock")
    @ResponseBody
    public String insertTaStock(TaStock taStock){
        System.out.println("增加TA库存");
        System.out.println(taStock.getDateTAStock());
        String dateTAStock = taStock.getDateTAStock();
        dateTAStock.trim();
        taStock.setSecurityAccrualStockId(dbutil.getMaxId3(TableIdUtil.TASID, TableNameUtil.TAS, TableTimeUtil.TASTime,dateTAStock));
        System.out.println(taStock);
        int i = taStockService.insertTaStock(taStock);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }

    @RequestMapping("deleteTaStock")
    @ResponseBody
    public  String deleteTaStock(TaStock taStock){
        System.out.println("删除TA库存");
        int i = taStockService.deleteTaStock(taStock);
        if (i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping("updateTaStock")
    @ResponseBody
    public  String updateTaStock(TaStock taStock){
        System.out.println("修改TA库存");
        int i = taStockService.updateTaStock(taStock);
        if (i>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
}
